package com.qf.application.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.application.commons.utils.R;
import com.qf.application.entity.User;
import com.qf.application.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @Value("${server.port}")
    private Integer port; // 获取yml中的端口号

    @GetMapping("/test")
    public R test() {
        return R.ok().put("data", port);
    }

    @GetMapping("/list")
    public R list() {
        return R.ok().put("data", userService.list());
    }

    @PostMapping("/page")
    public R page(@RequestBody Page<User> page) {
        return R.ok(userService.page(page));
    }

    @PostMapping("/save")
    public R save(@RequestBody User user) {
        return R.write(userService.save(user));
    }

    @PostMapping("/update")
    public R update(@RequestBody User user) {
        return R.write(userService.updateById(user));
    }

    @GetMapping("/info/{id}")
    public R info(@PathVariable Integer id) {
        return R.ok(userService.getById(id));
    }

    @PostMapping("/remove")
    public R remove(@RequestBody List<Integer> uidList) {
        return R.write(userService.removeBatchByIds(uidList));
    }
}
